<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>PyWebview</title>
  <script src="./preload.js"></script>
</head>
<body>
  <h1>PyWebview</h1>
  <script>
    window.call_js = function(msg) {
      console.log(`pyton call js: ${msg}`)
    }
    
    // pywebview.api is not guaranteed to be available on the window.onload event
    // Subscribe to the window.pywebviewready event instead to make sure that pywebview.api is ready.
    window.addEventListener('pywebviewready', ()=>{
      console.log('pywebview', pywebview, pywebview.state.foo)
      pywebview.api.call_python('ping').then(res => {
        console.log(res)
      })
    })
  </script>
</body>
</html>